package com.glsc.ngateway.common.base.repo.mysql.opmanagemain.performance;

import com.glsc.ngateway.common.base.domain.mysql.opmanagemain.performance.DayPerformance;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;


@Repository
public interface DayPerformanceRepository extends JpaRepository<DayPerformance, Integer>, JpaSpecificationExecutor<DayPerformance> {

    /**
     * 查找某个用户这一时间段内的总的有效工时
     *
     * @param
     * @return
     */
    @Query(value = "select sum( d.man_hour ) from t_day_performance d where  " +
            "d.user_oa_account = :userOaAccount  " +
            "and  d.post_name = :postName  " +
            "and d.create_time >= :startTime  " +
            "and d.create_time <= :endTime  ", nativeQuery = true)
    Integer findUserSumManHour(@Param("userOaAccount") String userOaAccount, @Param("postName") String postName, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);

    @Query(value = "select sum( d.man_hour ) from t_day_performance d where  " +
            "d.user_oa_account = :userOaAccount  " +
            "and d.create_time >= :startTime  " +
            "and d.create_time <= :endTime  ", nativeQuery = true)
    Integer findUserSumManHourNoPostName(@Param("userOaAccount") String userOaAccount, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);



    /**
     * 查找某个用户这一时间段内的总的主动工时
     *
     * @param userOaAccount
     * @param startTime
     * @param endTime
     * @return
     */
    @Query(value = "select sum( d.accord_hour ) from t_day_performance d where  " +
            "d.user_oa_account = :userOaAccount  " +
            "and d.create_time >= :startTime  " +
            "and d.create_time <= :endTime  ", nativeQuery = true)
    Integer findUserSumAccordHour(@Param("userOaAccount") String userOaAccount, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);


}
